package com.edward.service;


import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.edward.PagerModel;
import com.edward.model.CncaList;


public class CncaListManager extends HibernateDaoSupport {

	public void addCncaList(CncaList cncaList) {
		
		getHibernateTemplate().save(cncaList);
	}
	
	public void updateCncaList(CncaList cncaList) {
		
		getHibernateTemplate().update(cncaList);
	}
	
	public void deleteCncaList(int id){
		
		getHibernateTemplate().delete(getCncaList(id));
	}
	
	public CncaList getCncaList(int id){
		CncaList d =(CncaList)getHibernateTemplate().get(CncaList.class, id);
		return d;
	}
	

	@SuppressWarnings("unchecked")
	public List<CncaList> listCncaList() {
		return getHibernateTemplate().find("from CncaList");
	}

	
	@SuppressWarnings("unchecked")	
	public PagerModel pagerList(int start,int limit) {
		List <CncaList>list = getHibernateTemplate().find("from CncaList" );
		int total = list.size();
		int toIndex = start + limit;
		if(toIndex>total){
			toIndex =  total;
		}
		List <CncaList>datas = list.subList(start, toIndex);
		PagerModel pm = new PagerModel();
		pm.setTotal(total);
		pm.setDatas(datas);
		return pm;
		
	}
	


}



